package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.project.api.domain.response.ProjectTaskResponse;
import com.nbsaas.boot.project.data.entity.ProjectTask;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
/**
 * 项目任务-实体对象转化成响应对象
 */

public class ProjectTaskResponseConvert implements Converter<ProjectTaskResponse, ProjectTask> {

    @Override
    public ProjectTaskResponse convert(ProjectTask source) {
        ProjectTaskResponse result = new ProjectTaskResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCreator() != null) {
            result.setCreator(source.getCreator().getId());
        }

        try {
            if (source.getCreator() != null) {
                result.setCreatorName(source.getCreator().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getProject() != null) {
            result.setProject(source.getProject().getId());
        }
        if (source.getEntry() != null) {
            result.setEntry(source.getEntry().getId());
        }

        try {
            if (source.getExecutor() != null) {
                result.setExecutorName(source.getExecutor().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getExecutor() != null) {
            result.setExecutor(source.getExecutor().getId());
        }
        if (source.getState() != null) {
            result.setStateName(String.valueOf(source.getState()));
        }

        try {
            if (source.getProject() != null) {
                result.setProjectName(source.getProject().getName());
            }
        } catch (Exception ignored) {
        }

        return result;
    }

}

